package com.bd08.flink.demo.zhang

import org.apache.flink.api.common.functions.Partitioner
import org.apache.flink.api.scala.{ExecutionEnvironment, createTypeInformation}

object PartitionDemo extends App {
  class oddEvenPartitioner extends Partitioner[Int]{
    override def partition(k: Int, i: Int): Int = {
      //做分区定义时返回值始终是分区索引下标
      k%2 match{
        case 0=>0
        case 1=>1
      }}}
  val benv = ExecutionEnvironment.getExecutionEnvironment
  val ds=benv.fromCollection(List((1,true),(2,true),(3,false),(4,false)))
  ds.partitionCustom(new oddEvenPartitioner,0)
  .writeAsCsv("H:\\Module 14 - 项目部署\\demo1\\src\\main\\resources\\zhang", "\n", "|")
  benv.execute()
}
